<?php
//рус
class media_controlls_http_web extends controller_prototype_class
{
	private $_imageMapper;
	
    protected function GetImageMapper()
    {
		if (!$this->_imageMapper) 
		{
			include_once(_APP_PATH. "business/image/image_mapper.php");
			$this->_imageMapper = ImageMapper::GetInstance(); 
		}
		return $this->_imageMapper;     	
    } 	
	
	public function Get(MediaEntity $obj)
	{
		if ($obj->GetStatus() != MatchMediaStatus::Ready) return $this->GetThumb($obj);
		
		switch ($obj->type)
		{
			case 'photo': return $this->GetPhoto($obj);
			case 'video': return $this->GetVideo($obj);
			case 'audio': return $this->GetAudio($obj);
			default: return '';			
		}
	}

	public function GetThumb(MediaEntity $obj)
	{
        $t = $this->GetTemplator();
        $t->file = $obj;
        $t->folder = $this->GetPhotoThumbFolder('mediaadmin');
        return $t->render('media/_thumb.phtml');		
	}	
	
	public function GetPhoto(MediaEntity $obj)
	{
        $t = $this->GetTemplator();
        $t->file = $obj;
        $t->folder = $this->GetPhotoThumbFolder('mediaadmin');
        return $t->render('media/_photo.phtml');		
	}
	
	public function GetVideo(MediaEntity $obj)
	{
        $t = $this->GetTemplator();
        $t->file = $obj;
        $t->mediaFolder = MozgCfg::GetProp('global/media//mediaImageFolder');
        $t->folder = $this->GetPhotoThumbFolder('mediavideo');
        return $t->render('media/_video.phtml');		
	}

	public function GetAudio(MediaEntity $obj)
	{
        $t = $this->GetTemplator();
        $t->file = $obj;
        $t->mediaFolder = MozgCfg::GetProp('global/media//mediaImageFolder');
        $t->folder = $this->GetPhotoThumbFolder('mediavideo');
        return $t->render('media/_audio.phtml');		
	}

    protected function GetPhotoThumbFolder($thumbFolder)
    {
        return $this->GetImageMapper()->GetImageThumbFolder($thumbFolder);      
    }	
}